package com.iot.ic.modules.util;

import com.iot.ic.common.config.GlobalConfig;
import com.xiaomi.xmpush.server.Constants;
import com.xiaomi.xmpush.server.Message;
import com.xiaomi.xmpush.server.Result;
import com.xiaomi.xmpush.server.Sender;
import org.json.simple.parser.ParseException;

import java.io.IOException;


public class MiPushUtils {

    public static Result send(String content,String title, String description, String userRegId){
        Constants.useOfficial();
        String security = GlobalConfig.getConfig("xiaomi.push.security");
        String packageName = GlobalConfig.getConfig("xiaomi.push.package");
        System.out.println(" security="+security+" pack="+packageName);
        Sender sender = new Sender(security);
        Message message = new Message.Builder()
                .title(title)
                .description(description).payload(content)
                .restrictedPackageName(packageName)
                .notifyType(1)     // 使用默认提示音提示
                .build();
        try {
            Result result = sender.send(message, userRegId, 3);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
